package com.ruoyi.product.mapper;

import java.util.List;

import com.ruoyi.product.domain.ProductCategory;
import com.ruoyi.product.domain.Shopping.*;
import com.ruoyi.product.domain.SpecProduct;
import com.ruoyi.product.domain.vo.SpecProductVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * 商品管理表Mapper接口
 * 
 * @author cs
 * @date 2024-07-26
 */
public interface ManagementMapper 
{
    /**
     * 查询商品管理表
     * 
     * @param id 商品管理表主键
     * @return 商品管理表
     */
    public Management selectManagementById(Long id);

    /**
     * 查询商品管理表列表
     * 
     * @param management 商品管理表
     * @return 商品管理表集合
     */
    public List<Management> selectManagementList(Management management);

    /**
     * 新增商品管理表
     * 
     * @param management 商品管理表
     * @return 结果
     */
    public int insertManagement(Management management);

    /**
     * 修改商品管理表
     * 
     * @param management 商品管理表
     * @return 结果
     */
    public int updateManagement(Management management);

    /**
     * 删除商品管理表
     * 
     * @param id 商品管理表主键
     * @return 结果
     */
    public int deleteManagementById(Long id);

    /**
     * 批量删除商品管理表
     * 
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteManagementByIds(Long[] ids);

    @Select("select * from product_category where parent_id=1")
    List<ProductCategory> treeselect();

    @Select("select id, spec_name, product_name, product_prop from spec_product")
    List<SpecProductVo> specList();

    @Select("select * from spec_product where id=#{id}")
    SpecProduct selectSpecById(Long id);

    @Insert("insert into basic(type,product_name,unit,image,add_video,video,status,basic_snowflakes_id,collection,virtual_sales_volume,product_classify) values (#{type},#{productName},#{unit},#{image},#{addVideo},#{video},#{status},#{basicSnowflakesId},#{collection},#{virtualSalesVolume},#{productClassify})")
    int insertBasic(Basic basic);

    @Insert("insert into logistics(Logistics,postage,template,template_name,billing,distribution," +
            "first_piece,freight,continued,renewal,designated_free_shipping,free_shipping_area,specify_not_delivered," +
            "undelivered_regions,snowflakes_id,amount) values (#{logistics},#{postage},#{template},#{templateName}," +
            "#{billing},#{distribution},#{firstPiece},#{freight},#{continued},#{renewal},#{designatedFreeShipping}," +
            "#{freeShippingArea},#{specifyNotDelivered},#{undeliveredRegions},#{snowflakesId},#{amount})")
    int insertLogistics(Logistics logistics);

    @Insert("insert into details(detail,snowflakes_id) values (#{detail},#{snowflakesId})")
    int insertDetails(Details details);

    @Insert("insert into marketing(sales,sort,integral,associate_user_tags,exclusive_to_paid_members,minimum_purchase_quantity," +
            "purchase,purchase_restriction_type,purchase_limit,pre_sale,pre_sale_starttime,pre_sale_endtime,shipping_time," +
            "product_recommendations,activity_priority,snowflakes_id,ddsz,yjfy,ejfy,hyj) values (#{sales},#{sort},#{integral}," +
            "#{associateUserTags},#{exclusiveToPaidMembers},#{minimumPurchaseQuantity},#{purchase},#{purchaseRestrictionType}," +
            "#{purchaseLimit},#{preSale},#{preSaleStarttime},#{preSaleEndtime},#{shippingTime},#{productRecommendations}," +
            "#{activityPriority},#{snowflakesId},#{ddsz},#{yjfy},#{ejfy},#{hyj})")
    int insertMarketing(Marketing marketing);

    @Insert("insert into other(product_keywords,product_description,product_password,product_recommendation_image,snowflakes_id) values (" +
            "#{productKeywords},#{productDescription},#{productPassword},#{productRecommendationImage},#{snowflakesId})")
    int insertOther(Other other);

    @Insert("insert into specification(image,market,cost,price,inventory,snowflakes_id,weight,volume,spec_product_id,specName) values" +
            " (#{image},#{market},#{cost},#{price},#{inventory},#{snowflakesId},#{weight},#{volume},#{specProductId},#{specName})")
    int insertSpecification(Specification specification);

    @Update("update basic set status =#{status} where id=#{id}")
    int change(Management management);

    @Select("select b.product_name 'basic.productName',d.detail 'details.detail' from basic b left join specification s on b.basic_snowflakes_id=s.snowflakes_id\n" +
            "                              left join details d on b.basic_snowflakes_id=d.snowflakes_id\n" +
            "                              left join logistics l on b.basic_snowflakes_id=l.snowflakes_id\n" +
            "                              left join marketing m on b.basic_snowflakes_id=m.snowflakes_id\n" +
            "                              left join other o on b.basic_snowflakes_id=o.snowflakes_id")
    List<SUM> selectTest();

    List<SUM> selectSumList(Management management);
}
